var t = require("../../utils/city.js"), e = require("../../utils/api.js"), a = getApp();

Page({
    data: {
        searchLetter: [],
        showLetter: "",
        winHeight: 0,
        tHeight: 0,
        bHeight: 0,
        startPageY: 0,
        cityList: [],
        isShowLetter: !1,
        scrollTop: 0,
        city: ""
    },
    onLoad: function(i) {
        var o = this;
        wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        });
        var r = t.searchLetter, s = a.globalData.city, n = a.globalData.cid;
        o.setData({
            city: s,
            cid: n
        }), console.log(o.data.city), e.GetCityList().then(function(t) {
            0 == t.errno && o.setData({
                cityList: t.data
            });
        });
        for (var c = wx.getSystemInfoSync().windowHeight, h = c / r.length, g = [], l = 0; l < r.length; l++) {
            var u = {};
            u.name = r[l], u.tHeight = l * h, u.bHeight = (l + 1) * h, g.push(u);
        }
        this.setData({
            winHeight: c,
            itemH: h,
            searchLetter: g
        }), console.log(o.data.cityList);
    },
    searchStart: function(t) {
        console.log(t);
        var e = t.currentTarget.dataset.letter, a = t.touches[0].pageY;
        this.setScrollTop(this, e), this.nowLetter(a, this), this.setData({
            showLetter: e,
            startPageY: a,
            isShowLetter: !0
        });
    },
    searchMove: function(t) {
        var e = t.touches[0].pageY, a = this.data.startPageY, i = this.data.tHeight, o = this.data.bHeight;
        console.log(e), a - e > 0 ? e < i && this.nowLetter(e, this) : e > o && this.nowLetter(e, this);
    },
    searchEnd: function(t) {
        var e = this;
        setTimeout(function() {
            e.setData({
                isShowLetter: !1
            });
        }, 1e3);
    },
    nowLetter: function(t, e) {
        for (var a = this.data.searchLetter, i = 0, o = 0, r = "", s = 0; s < a.length; s++) if (a[s].tHeight <= t && t <= a[s].bHeight) {
            i = a[s].bHeight, o = a[s].tHeight, r = a[s].name;
            break;
        }
        this.setScrollTop(e, r), e.setData({
            bHeight: i,
            tHeight: o,
            showLetter: r,
            startPageY: t
        });
    },
    bindScroll: function(t) {},
    setScrollTop: function(t, e) {
        var a = 0, i = t.data.cityList;
        console.log(i);
        var o = 0, r = 0;
        for (var s in i) {
            if (console.log(o), console.log(r), console.log(i[s]), e === s) return a = 21 * r + 41 * o, 
            t.setData({
                scrollTop: a
            }), !1;
            r++, o += i[s].cityInfo.length;
        }
        return !1;
    },
    bindCity: function(t) {
        var e = t.currentTarget.dataset.city, a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "../group/groupList?act=selected&&city=" + e + "&&cid=" + a
        });
    }
});